<template>
  <div  >

    <div  class="replyinfo"  v-loading="loading">
        <div    v-for="item in replyList">
          <div class=" mt5 mb5">{{item.createTime}}</div>
          <div class="cl mt5 mb5">{{item.sendNickName}}回复：</div>
          <div class="reply_content">{{item.content}}</div>
          <br/>
        </div>
        <pagination
          v-show="total>0"
          :total="total"
          :page-sizes="[3, 6, 10, 20]"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      <div class="no_reply"  v-if="replyList.length==0">
        暂无消息
      </div>
    </div>

    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-input v-model="form.content" placeholder="请输入你想发送的内容"  type="textarea" :rows="4"/>
         <div  class="mt10 " style="text-align: left">
           <el-button type="danger" v-if="status!='3' &&  type=='1'" @click="handleJan">结案</el-button>
           <el-button type="primary" v-if="type=='1'"   @click="sendSubmitForm">发送</el-button>
         </div>
    </el-form>
    <!-- 添加或修改服务回复对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>-->

<!--        <el-form-item label="评论内容">-->
<!--          <editor v-model="form.content" :min-height="192"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="业务Id" prop="businessId">-->
<!--          <el-input v-model="form.businessId" placeholder="请输入业务Id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="发送用户Id" prop="sendUserId">-->
<!--          <el-input v-model="form.sendUserId" placeholder="请输入发送用户Id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="接收用户Id" prop="receiveUserId">-->
<!--          <el-input v-model="form.receiveUserId" placeholder="请输入接收用户Id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="删除标志" prop="delFlag">-->
<!--          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="${comment}" prop="remark">-->
<!--          <el-input v-model="form.remark" placeholder="请输入${comment}" />-->
<!--        </el-form-item>-->


<!--    </el-dialog>-->
  </div>
</template>

<script>
import { listReply, getReply, delReply, addReply, updateReply } from "@/api/business/reply";

import { listSq, getSq, delSq, addSq, updateSq, addSqReply, updateJan } from '@/api/business/knbfsq'
import { getDbNum } from '@/api/business/tjfx'

export default {
  name: "ReplyList",
  props: {
    businessId: {
      type: String,
      required: true
    },
    status: {
      type: String,
      required: true
    },
    type: {
      type: String
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 服务回复表格数据
      replyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 3,
        content: null,
        businessId: null,
        sendUserId: null,
        receiveUserId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        content: [
          { required: true, message: "内容不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询服务回复列表 */
    getList() {
      this.loading = true;
      this.queryParams.businessId = this.businessId;
      listReply(this.queryParams).then(response => {
        this.replyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        content: null,
        businessId: null,
        sendUserId: null,
        receiveUserId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加服务回复";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getReply(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改服务回复";
      });
    },
    handleJan(){
      this.form.businessId = this.businessId;
      const  formdata=this.form
      this.$modal.confirm('确定结案吗？').then(function() {
        return updateJan(formdata);
      }).then(() => {
        this.getList();
        this.getDbNum();
        this.$modal.msgSuccess("成功");
        // 结案 给父组件通知 关闭 弹窗
        this.$emit('toCloseReply');
      }).catch(() => {});

    },
    sendSubmitForm() {
      this.form.businessId = this.businessId;
      if(!this.form.content){
        this.$modal.msgError("内容不能为空");
        return;
      }
      addSqReply(this.form).then(response => {
        this.$modal.msgSuccess("发送成功");
        this.open = false;
        this.form.content = null;
        this.getList();
        this.getDbNum();
        this.$emit('sxlist');
      });
    },
    getDbNum() {
      getDbNum().then(res => {
        // 将数量放入vuex中
        this.$store.commit('SET_DBNUM', res.data)
      })
    },
    /** 提交按钮 */
    submitForm() {
      if(!this.form.content){
        this.$modal.msgError("内容不能为空");
        return;
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReply(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReply(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除服务回复编号为"' + ids + '"的数据项？').then(function() {
        return delReply(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/reply/export', {
        ...this.queryParams
      }, `reply_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.replyinfo {
  min-height: 100px;
  overflow-y: auto;
  border: 1px solid #dcdfe6;
  margin: 10px 0px;
  padding: 10px;
}
.cl{
  color: red;
}
.reply_content{
  max-height: 100px;
  overflow-y: auto;
}
.no_reply{
  text-align: left;
}

</style>

